<?php
class TicketController extends Zend_Controller_Action
{
	protected $_acl;
	protected $_userGroup;
	
	public function init()
	{
		$auth = Zend_Auth::getInstance();
		$userInfo = $auth->getStorage()->read();
		$groupBase = new GroupBase();
		if ($userInfo) {
			$userGroups = $groupBase->getUserGroup($userInfo->name);
		}
		$this->_userGroup = $userGroups[0]['name'] ? $userGroups[0]['name'] : "Users";
		$this->_acl = new Acl_PPMIS();
		$this->view->acl = $this->_acl;
		$this->view->userGroup = $this->_userGroup;
	}
	
	public function preDispatch()
	{
		$auth = Zend_Auth::getInstance();
		if($auth->getIdentity()) {
			$this->view->auth = "success";
			$userInfo = $auth->getStorage()->read();
			$this->view->userInfo = $userInfo;
		}
		$Configuration = new Configuration();
		$configurationData = $Configuration->getConfigurationInfo();
		$this->view->configuration = $configurationData;
	}
	
	public function indexAction()
	{
		$id = $this->_getParam('id',1);
		$ticket = new Ticket();
		$data = $ticket->fetchRow($ticket->select()->where('id = ?',$id));
		
		$ticketChange = new TicketChange();
		
		$comments = $ticketChange->fetchAll($ticketChange->select()->where('ticket',$id));
		
		$this->view->comments = $comments->toArray();
		$this->view->data = $data->toArray();
	}
	
	public function newAction()
	{
		
	}
	
	public function attachmentAction()
	{
		$id = $this->_getParam('id',1);
		$ticket = new Ticket();
		$data = $ticket->fetchRow($ticket->select()->where('id = ?',$id));
		$this->view->data = $data->toArray();
	}
}
